{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<img align=\"left\" style=\"padding-right:10px;\" src=\"figures/PHydro-cover-small.png\">\n",
    "*This is the Jupyter notebook version of the [Python in Hydrology](http://www.greenteapress.com/pythonhydro/pythonhydro.html) by Sat Kumar Tomer.*\n",
    "*Source code is available at [code.google.com](https://code.google.com/archive/p/python-in-hydrology/source).*\n",
    "\n",
    "*The book is available under the [GNU Free Documentation License](http://www.gnu.org/copyleft/fdl.html). If you have comments, corrections or suggestions, please send email to satkumartomer@gmail.com.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Data Structures](02.02-Data-Structures.ipynb) | [Contents](Index.ipynb) | [Operators and Operands](02.04-Operators-and-Operands.ipynb)>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "那么变量的名称应该是有意义的，并且可能应该记录变量的用途。\n",
    "\n",
    "变量名可以是任意长的。它们既可以包含字母也可以包含数字，但它们必须以字母开头。它使用大写字母是合法的，但变量名最好以小写字母开始，因为传统上大写字母用来表示类。下划线字符`(_)`可以出现在一个名字中。它通常用于带有多个单词的名称，如`my_name`或`airspeed_of_unladen_swallow`。变量名可以以下划线的方式开头，但是应该避免，因为这是常规使用的东西。\n",
    "\n",
    "Python有一些保留的关键字，这些不能用作变量名。如果解释器给出了有关你一个变量名的错误，你不知道为什么，你应该检查你的变量名是否不在保留关键字列表中。记住这个列表或掌握它是个好主意。但是，作为一个懒惰的人，我并不记得这个列表，实际上甚至从来没有想过要记住。我只是键入在Python中想要使用的变量名称，并通过python查找输出，然后决定是否使用这个名称的变量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-1-44d3081ae1ac>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-1-44d3081ae1ac>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    500_mangoes\u001b[0m\n\u001b[1;37m              ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "500_mangoes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-2-20a882c5c27d>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-2-20a882c5c27d>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    class\u001b[0m\n\u001b[1;37m         ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<module 'numpy' from 'd:\\\\anaconda3\\\\envs\\\\dataprocess\\\\lib\\\\site-packages\\\\numpy\\\\__init__.py'>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'foo' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-6-d3b07384d113>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mfoo\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'foo' is not defined"
     ]
    }
   ],
   "source": [
    "foo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第一个变量名为`500_mangoes`给出了语法错误(SyntaxError)，所以我们不能使用这个名称作为变量。`class`同样给出了语法错误，所以也同样不能使用。`np`给出了一些输出(意味着`np`是指某些东西)，所以如果我们使用这个作为变量名，引用将会被摧毁。`foo`给出了NameError(名称错误)表明变量名未定义，这使得它成为变量名的有效选择。除这些情况外，还有一个输出时可能的："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 5\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这表明变量`a`是之前定义的，现在取决于你，如果你想改变旧的值。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
